package br.gfca.lanhostfinder;

public class LANPoller implements Runnable {
	
	String networkAddr;
	int pingTimeout;
	boolean[] foundHosts;
	int totalCycleTime;
	
	public LANPoller( String networkAddr, int pingTimeout, boolean[] foundHosts, int totalCycleTime ) {
		this.networkAddr = networkAddr;
		this.pingTimeout = pingTimeout;
		this.foundHosts = foundHosts;
		this.totalCycleTime = totalCycleTime;
	}

	@Override
	public void run() {
		try {
			while( true ) {
				for( int i = 1; i <= 254; i++ ) {
					new Thread( new RunnableHostFinder( this.foundHosts, this.networkAddr + i, this.pingTimeout ) ).start();
					Thread.sleep( (this.totalCycleTime * 1000) / 254 );
				}
			}
		}
		catch (Exception e) {
			System.out.println("==== LAN Poller terminated ====");
			e.printStackTrace();
			System.exit(0);
		}
	}

}
